<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="postList">
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <div>{{ scope.row.type == 0 ? '建议' : '缺陷' }}</div>
        </template>
      </el-table-column>
      <el-table-column label="反馈内容" align="center" prop="content"/>
      <el-table-column label="反馈时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-preventReClick
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
          >详情
          </el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div
      v-if="curRole[0]!=='admin'"
      class="feedbackBox"
      style="
        background: rgba(229, 229, 229, 0.2);
        padding: 15px;
        margin-top: 40px;
      "
    >
      <el-radio-group v-removeAriaHidden v-model="type">
        <el-radio :label="0">建议</el-radio>
        <el-radio :label="1">缺陷</el-radio>
      </el-radio-group>
      <el-input
        style="margin-top: 10px"
        type="textarea"
        :rows="6"
        placeholder="请输入内容"
        v-model="textarea"
        maxlength="500"
        show-word-limit
      >
      </el-input>
      <div class="flexEnd" style="margin-top: 10px">
        <el-button
          v-preventReClick
          type="primary"
          round
          size="mini"
          @click="handleFeedback"
        >反馈
        </el-button
        >
      </div>
    </div>
    <!-- 添加或修改岗位对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
    >
      <el-form @submit.native.prevent ref="form" :model="form" :rules="rules" label-width="70px">
        <el-form-item label="类型" prop="type">
          {{ form.type == 0 ? '建议' : '缺陷' }}
        </el-form-item>
        <el-form-item label="反馈内容" prop="content">
          {{ form.content }}
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-right">
        <el-button v-preventReClick type="primary" @click="cancel"
        >关 闭
        </el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {
  listPost_feedback,
  getPost_feedback,
  addPost_feedback
} from '@/api/helpFeedback/feedback'
import { parseTime } from '@/utils/cc'

export default {
  name: 'Post',
  dicts: ['sys_normal_disable'],
  data() {
    return {
      textarea: '',
      type: 0,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      activeIndex: '',
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  computed: {
    ...mapGetters(['curRole'])
  },
  created() {
    this.getList()
  },
  methods: {
    parseTime,
    handleFeedback() {
      this.$modal
        .confirm('是否确认提交反馈？')
        .then(() => {
          addPost_feedback({
            content: this.textarea,
            type: this.type
          }).then(() => {
            this.textarea = ''
            this.getList()
            this.$modal.msgSuccess('反馈成功')
          })
        })
        .catch(() => {
        })
    },
    /** 查询岗位列表 */
    getList() {
      this.loading = true
      listPost_feedback(this.queryParams).then((response) => {
        this.postList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {}
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      this.reset()
      const feedbackId = row.feedbackId || this.ids
      getPost_feedback(feedbackId).then((response) => {
        this.form = response.data
        this.open = true
        this.title = '详情'
      })
    }
  }
}
</script>
